package com.weipai.demo.controller;

import com.weipai.demo.enums.RetCode;
import com.weipai.demo.model.DUser;
import com.weipai.demo.service.UserService;
import com.weipai.demo.util.JPushUtil;
import com.weipai.demo.util.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Auther: gusl
 * @Date: 2019/5/31 10:33
 * @Description:用户模块
 */
@RestController
public class UserController {
    private final Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private UserService userService;


    /**
     *  登录
     *
     * @author gusl
     * @date 2019/5/31 10:34
     * @param  [username, password, request]
     * @return com.weipai.springboot.model.api.Response
     *
     */
/*    @RequestMapping(value = "/user/login")
    public Response login(String userName, String password, int type, HttpServletRequest request) {
        logger.info("/user/login:username:"+userName+",password:"+password+",source:"+type);
        return userService.login(userName, password, type);
    }*/




    //登录
    @RequestMapping(value = "/user/login")
    public Response login(DUser dUser) {
        logger.info("/user/login:username:"+dUser);
        return userService.login(dUser);
    }

    //退出
    @RequestMapping(value = "/user/loginOut")
    public Response loginOut() {
        return userService.loginOut();
    }


    /**
     * 管理员重置密码
     *
     * @param oldPassword：旧密码
     * @param newPassword：新密码
     * @param twoPassword：新密码确认
     * @return
     */
    @RequestMapping(value = "/user/resetUserPassword",method = RequestMethod.POST)
    public Response resetUserPassword( String oldPassword,
                                       String userName,
                                       String newPassword,
                                       String twoPassword,
                                       Integer id) {
        return userService.resetUserPassword(userName, oldPassword, newPassword, twoPassword,id);
    }

}
